package com.allenkerr;

import java.util.Map;

import org.elasticsearch.client.Client;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;

@SpringBootApplication
public class Demo11EsApplication implements CommandLineRunner {

    @Autowired
    private ElasticsearchTemplate esTemplate;

    public static void main(String[] args) {
        SpringApplication.run(Demo11EsApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        this.printElasticSearchInfo();
    }

    //useful for debug, print elastic search details
    private void printElasticSearchInfo() {
        System.out.println("--ElasticSearch--");
        
        Client client = esTemplate.getClient();
        Map<String, String> asMap = client.settings().getAsMap();
        asMap.forEach((k, v) -> System.out.println(k + " = " + v));
        
        System.out.println("--ElasticSearch--");
    }
}
